package archer.back.models

import java.sql.Timestamp
import java.util.Date

import io.circe.{ Decoder, Encoder }
import io.circe.generic.auto._

import utils.CirceUtils

import scala.language.implicitConversions

case class NewsInfo(title: String, updateTime: Date)

object NewsInfo extends CirceUtils {

  implicit val dateEncoder: Encoder[Date] = timestampEncoderFromPattern(
    "yyyy-MM-dd HH:mm:ss.SSS").contramap((s: Date) => new Timestamp(s.getTime))
  implicit val dateDecoder: Decoder[Date] = timestampDeocderFromPattern(
    "yyyy-MM-dd HH:mm:ss.SSS").map(s => new Date(s.getTime))

  implicit val encoder = implicitly[Encoder[NewsInfo]]
  implicit val decoder = implicitly[Decoder[NewsInfo]]

}
